<table class="table">
    <thead>
        <tr>
            <th style="border-bottom-color: #00a7d0;width: 120px;"><input type="checkbox" class="grid-select-all" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SKU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
            <th style="border-bottom-color: #00a7d0">关联SKU</th>
            <th style="border-bottom-color: #00a7d0">品类</th>
            <th style="border-bottom-color: #00a7d0">在库</th>
            <th style="border-bottom-color: #00a7d0">组合数量</th>
            <th style="border-bottom-color: #00a7d0;width: 15%">产品名称</th>
            <th style="border-bottom-color: #00a7d0">操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach($paginator as $row)
            @php
                $mixRuleArr = \App\Models\Product\ProductMixSku::_mixRuleArrIDAsKey($row->mix_rule);
                $cSku = \App\Admin\Controllers\Inventory\MixController::getMixInventory($mixRuleArr);
                $num = \App\Admin\Ajax\Inventory\MixAjax::mixSku($mixRuleArr);
            @endphp
            <tr>
                <td style="border-top-color: #00a7d0"><input type="checkbox" class="grid-row-checkbox" data-id="{{ $row->id }}" />&nbsp;&nbsp;{{ $row->psku_code }}</td>
                <td style="border-top-color: #00a7d0"></td>
                <td style="border-top-color: #00a7d0"><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $row->classify->title ?? '' }}</span></td>
                <td style="border-top-color: #00a7d0">{{ \App\Models\Inventory\Timely::getInstant($row->id) }}</td>
                <td style="border-top-color: #00a7d0">
                    <input type="text" class="mix_num_" style="width: 100px; text-align: right;" name="mix_num" data-max="{{ $num }}" value="{{ $num }}">
                </td>
                <td style="border-top-color: #00a7d0"><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $row->psku_cn }}</span></td>
                <td style="border-top-color: #00a7d0">
                    <button class="btn btn-xs btn-info grid-batch-check" data-id="{{ $row->id }}">组合</button>
                </td>
            </tr>
            @foreach($cSku as $item)
                <tr>
                    <td></td>
                    <td>{{ $item['sku'] }}</td>
                    <td><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $item['title'] }}</span></td>
                    <td>{{ $item['instant'] }}{{ '(PUBLIC)' }}</td>
                    <td></td>
                    <td><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $item['sku_cn'] }}</span></td>
                    <td></td>
                </tr>
            @endforeach
        @endforeach
    </tbody>
</table>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('.grid-select-all').iCheck({checkboxClass:'icheckbox_minimal-blue'});
        $('.grid-select-all').on('ifChanged', function(event) {
            if (this.checked) {
                $('.grid-row-checkbox').iCheck('check');
            } else {
                $('.grid-row-checkbox').iCheck('uncheck');
            }
        });
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });
        $('.grid-batch-check').on('click', function() {
            var id = $(this).data('id');
            var tr = $(this).closest('tr');
            var detail = {};
            var indexArr = {};
            indexArr['psku_id'] = id;
            indexArr['mix_num'] = tr.find('input[name="mix_num"]').val();
            detail[0] = indexArr;
            $.ajax({
                method: 'post',
                url: '/xqc/inventory/mix-ajax',
                data: {
                    _token:"{{ csrf_token() }}",
                    param: detail,
                    action: 'mixBatch'
                },
                success: function (data) {
                    if (typeof data === 'object') {
                        if (data.status) {
                            toastr.success('提交成功 !');
                            $.pjax.reload('#pjax-container');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
            });
        });
    });
</script>
